package com.na.tools.texturesplit;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.util.Collection;

import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

public class TexturePanel extends JPanel {

	public TexturePanel() {
	}
	
	public void clearTextureFrames() {
	}
	
	public void addTextureFrames(Collection<TextureFrame> frames) {
		int cols = 5;
		int rows = (frames.size() + cols - 1) / cols;
		removeAll();
		setLayout(new GridLayout(rows, cols));
		for (TextureFrame frame : frames) {
			add(new Grid(frame));
		}
		setBorder(BorderFactory.createLineBorder(Color.RED, 2));
		SwingUtilities.invokeLater(new Runnable() {
			@Override
			public void run() {
				invalidate();
				repaint();
			}
		});
	}
	
	private static class Grid extends JComponent {

		private TextureFrame frame;
		
		private Grid(TextureFrame frame) {
			this.frame = frame;
		}
		
		@Override
		protected void paintComponent(Graphics g) {
//			super.paintComponent(g);
//			frame.paint(g, getX(), getY(), getWidth(), getHeight());
		}
		
	}
	
}
